package cn.zswltech.gruul.biz.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.zswltech.gruul.biz.service.ResourceService;
import cn.zswltech.gruul.common.constant.MenuConstants;
import cn.zswltech.gruul.common.dal.dao.MenuDOMapper;
import cn.zswltech.gruul.common.dal.dao.ResourceDOMapper;
import cn.zswltech.gruul.common.dto.ResourceViewREQ;
import cn.zswltech.gruul.common.dto.ResourceViewRSP;
import static cn.zswltech.gruul.web.api.util.GruulUtil.*;

import cn.zswltech.gruul.common.dto.RoleMenuResourceRSP;
import cn.zswltech.gruul.common.entity.MenuDO;
import cn.zswltech.gruul.common.entity.ResourceDO;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Jim
 * @version 1.0.0
 * @descripition:
 * @date 2024/3/21 15:36
 */
@Service
@Slf4j
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private ResourceDOMapper resourceDOMapper;

    @Autowired
    private MenuDOMapper menuDOMapper;

    @Override
    public ResourceViewRSP systemResource(ResourceViewREQ req) {
        checkSystemCode();
        // 系统下辖菜单
        List<MenuDO> menuDOList = menuDOMapper.selectByExample(Example.builder(MenuDO.class).andWhere(Sqls.custom().andEqualTo("systemCode", getSystemCode())).build());
        if (ObjectUtil.isEmpty(menuDOList)){
            log.info("系统（{}）没有菜单", getSystemCode());
            return null;
        }
        List<MenuDO> rootMenus = menuDOList.stream().filter(item -> item.getParentId() == null).collect(Collectors.toList());
        for (MenuDO rootMenu : rootMenus) {
            List<MenuDO> menuDOS = menuDOMapper.menuTreeListByRootId(rootMenu.getId());
            buildSingleMenu(menuDOS)
        }



        return null;
    }

    private ResourceViewRSP.SingleMenu buildSingleMenu(List<MenuDO> menuDOS) {
        ResourceViewRSP.SingleMenu singleMenu = new ResourceViewRSP.SingleMenu();

        return singleMenu;
    }


}
